-- SPDX-License-Identifier: GPL-3.0-or-later

local v_shitian = fk.CreateSkill {
  name = "v_shitian",
  tags = {  },
}

--时机：阶段开始时
v_shitian:addEffect(fk.EventPhaseStart, {
  --默认播放配音，可以通过Mute=true关闭技能配音。
  mute = true,
  --赋予支援型技能定义
  anim_type = "support", 
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能、遍历到的角色处于准备阶段。
  can_trigger = function(self, event, target, player, data) 
    return target == player and player:hasSkill(v_shitian.name) and
      player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --播放技能语音
    room:notifySkillInvoked(player, v_shitian.name)
    player:broadcastSkillInvoke(v_shitian.name)
    local to = player
    local judge = {
      who = to,
      reason = v_shitian.name,
      pattern = ".|.|heart,diamond",
    }
    room:judge(judge)
    if judge:matchPattern() then
      player:drawCards(1, v_shitian.name)
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = v_shitian.name,
      }
      --彩蛋标签准备
      room:setPlayerMark(player, "v_shitian_failed", 0)
      room:delay(500)
    else
      if player:getMark("v_shitian_failed") >= 1 then
        local address = "./packages/VirtualSlash/image/anim/v_shitian_failed"
        room:setEmotion(player, address)
      else
        room:addPlayerMark(player, "v_shitian_failed", 1)
      end
    end
  end,
})

-- TODO:等官方搞出基础AI再说吧，现在不算很靠谱
-- v_shitian:addAI({
--   think_skill_invoke = function(self, ai, skill_name, prompt)
--     return true
--   end,
-- })

return v_shitian